package com.sven.helloconsumer;

import com.sven.helloapi.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class HelloController {

    @Value("${server.port}")
    String port;

    @Autowired
    private HelloFeginService helloFeginService;

    @RequestMapping(value = "/hello1", method = RequestMethod.GET)
    String hello1(){
        // int i=1/0;
        return "consumer：端口是"+port+">>>"+helloFeginService.hello1();
    }

    @RequestMapping(value = "/hello2", method = RequestMethod.GET)
    String hello2(@RequestParam Map<String, Object> map){
        System.out.println(map);
        User user = new User();
        user.setName(map.get("name").toString()+"，你好777");
        user.setAge(1000111);
        return helloFeginService.hello8(user);
    }

    @RequestMapping(value = "/hello6", method = RequestMethod.GET)
    String hello6(String name){
        return helloFeginService.hello6(name);
    }

    @RequestMapping(value = "/hello66", method = RequestMethod.GET)
    String hello66(@RequestParam(value = "name") String name){
        return helloFeginService.hello6(name);
    }

    @RequestMapping(value = "/hello7", method = RequestMethod.GET)
    User hello7(@RequestHeader("name") String name, @RequestHeader("age") Integer age){
        return helloFeginService.hello7(name, age);
    }

    @RequestMapping(value = "/hello8", method = RequestMethod.POST)
    String hello8(@RequestBody User user){
        int i=1/0;
        return helloFeginService.hello8(user);
    }

    @RequestMapping(value = "/hello88", method = RequestMethod.POST)
    String hello88(@RequestBody Map<String, Object> map){
        System.out.println(map);
        User user = new User();
        user.setName(map.get("name").toString()+"，你好777");
        user.setAge(1000111);
        return helloFeginService.hello8(user);
    }
}
